package io.geekidea.boot.test.controller;

import io.geekidea.boot.framework.page.Paging;
import io.geekidea.boot.framework.response.ApiResult;
import io.geekidea.boot.test.query.AppCarsQuery;
import io.geekidea.boot.test.service.CarsService;
import io.geekidea.boot.test.vo.AppCarsVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

/**
 * App车辆 控制器
 *
 * @author geekidea
 * @since 2025-03-26
 */
@Slf4j
@RestController
@Tag(name = "App车辆")
@RequestMapping("/app/cars")
public class AppCarsController {

    @Autowired
    private CarsService carsService;

    /**
     * 获取App车辆详情
     *
     * @param id
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App车辆详情")
    @PostMapping("/getAppCars/{id}")
    public ApiResult<AppCarsVo> getAppCars(@PathVariable Long id) {
        log.info("获取App车辆详情：{}", id);
        AppCarsVo appCarsVo = carsService.getAppCarsById(id);
        return ApiResult.success(appCarsVo);
    }

    /**
     * 获取App车辆分页列表
     *
     * query
     * @return
     * @throws Exception
     */
    @Operation(summary = "获取App车辆分页列表")
    @PostMapping("/getAppCarsPage")
    public ApiResult<AppCarsVo> getAppCarsPage(@Valid @RequestBody AppCarsQuery query) {
        log.info("获取App车辆分页列表：{}", query);
        Paging<AppCarsVo> paging = carsService.getAppCarsPage(query);
        return ApiResult.success(paging);
    }

}
